using System.Collections.Generic;
using Engine.Core.Interfaces;
using Engine.Particles.Interfaces;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Engine.Particles.Effects
{
    public class ShotEffect : IParticleEffect
    {
        public bool HasEnded
        {
            get { return _particle.TimeToLive <= 0; }
        }

        public Texture2D Texture { get; set; }

        public Vector2 EmitterLocation { get; set; }

        public Vector2 Direction { get; set; }

        private Particle _particle;
        private bool _effectCreated;


        public static ShotEffect Create(Texture2D texture, Vector2 emitterLocation, Vector2 direction)
        {
            return new ShotEffect()
                       {
                           Texture = texture,
                           EmitterLocation = emitterLocation,
                           Direction = direction
                       };
        }



        public void Update(GameTime gameTime){
            if (!_effectCreated) {
                _particle = Particle.Create(Texture, EmitterLocation, Color.White, 1f, 10000, Direction);
                _effectCreated = true;
            }
            _particle.Update(gameTime);

        }

        public List<IExtendedDrawable> GetDrawables() {
            return new List<IExtendedDrawable>() {_particle};
        }

        public List<IPhysicElement> GetPhysicObjects() {
            return new List<IPhysicElement> {_particle};
        }
    }
}